﻿using System;
namespace ShapeAreaCalculator
{
    public abstract class Shape
    {
        public abstract double CalculateArea();
        public abstract bool IsValid();
    }

    public class Rectangle : Shape
    {
        public double Length { get; }
        public double Width { get; }
        public Rectangle(double length, double width)
        {
            Length = length;
            Width = width;
        }
        public override double CalculateArea() => IsValid() ? Length * Width : 0;
        public override bool IsValid() => Length > 0 && Width > 0;
    }
    public class Square : Shape
    {
        public double Side { get; }
        public Square(double side) => Side = side;
        public override double CalculateArea() => IsValid() ? Side * Side : 0;
        public override bool IsValid() => Side > 0;
    }
    public class Circle : Shape
    {
        public double Radius { get; }
        public Circle(double radius) => Radius = radius;
        public override double CalculateArea() => IsValid() ? Math.PI * Radius * Radius : 0;
        public override bool IsValid() => Radius > 0;
    }
    class Program
    {
        static void Main(string[] args)
        {
            var shapes = new List<Shape>();
            var random = new Random();
            for (int i = 0; i < 10; i++)
            {
                Shape shape = random.Next(3) switch
                {
                    0 => new Rectangle(GetRandomSize(random), GetRandomSize(random)),
                    1 => new Square(GetRandomSize(random)),
                    2 => new Circle(GetRandomSize(random)),
                    _ => throw new InvalidOperationException()
                };
                shapes.Add(shape);
            }
            double totalArea = 0;
            foreach (var shape in shapes)
            {
                totalArea += shape.CalculateArea();
            }
            Console.WriteLine($"Total area of valid shapes: {totalArea:N2}");
        }
        static double GetRandomSize(Random rand)
        {
            // 生成 [-10, 10) 的随机参数
            const double range = 20;
            const double min = -10;
            return rand.NextDouble() * range + min;
        }
    }
}